package org.lion.jingbeifang_interviewquestions.calculatePrice;

import org.junit.jupiter.api.Test;
import org.lion.jingbeifang_interviewquestions.calculatePrice.entity.Goods;
import org.lion.jingbeifang_interviewquestions.calculatePrice.entity.StrategyDiscount;
import org.lion.jingbeifang_interviewquestions.calculatePrice.entity.StrategySubtract;
import org.lion.jingbeifang_interviewquestions.calculatePrice.enums.GoodsItem;
import org.lion.jingbeifang_interviewquestions.calculatePrice.service.CalculateWithSubtract;
import org.lion.jingbeifang_interviewquestions.calculatePrice.service.CommonCalculate;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

public class GoodsCalculate {
    StrategyDiscount noDiscount = new StrategyDiscount(1.0);
    Goods apple = new Goods(GoodsItem.APPLE,5,noDiscount);
    Goods strawberry = new Goods(GoodsItem.STRAWBERRY,10,noDiscount);
    Goods mango = new Goods(GoodsItem.MANGO,3,noDiscount);

    //8折
    StrategyDiscount discount = new StrategyDiscount(0.8);
    Goods strawberryWithDiscount = new Goods(GoodsItem.STRAWBERRY,10,discount);

    StrategySubtract subtract = new StrategySubtract(BigDecimal.valueOf(100),BigDecimal.valueOf(10));

    CommonCalculate commonCalculateService = new CommonCalculate();
    CalculateWithSubtract calculateWithSubtractService = new CalculateWithSubtract();

    /**
     * 题目1:无折扣正常计算价格 苹果+草莓
     */
    @Test
    public void calculateGoodsPrice(){
        List<Goods> goodsList = new ArrayList<>();
        goodsList.add(apple);
        goodsList.add(strawberry);

        BigDecimal totalPrice = commonCalculateService.calculateGoodsPrice(goodsList);
        System.out.println("price:"+totalPrice);
    }

    /**
     * 题目2:无折扣正常计算价格 苹果+草莓+芒果
     */
    @Test
    public void calculateGoodsPrice_2(){
        List<Goods> goodsList = new ArrayList<>();
        goodsList.add(apple);
        goodsList.add(strawberry);
        goodsList.add(mango);

        BigDecimal totalPrice = commonCalculateService.calculateGoodsPrice(goodsList);
        System.out.println("price:"+totalPrice);
    }

    /**
     * 题目3:草莓折扣计算价格
     */
    @Test
    public void calculateGoodsPriceWithDiscount(){
        List<Goods> goodsList = new ArrayList<>();
        goodsList.add(apple);
        goodsList.add(strawberryWithDiscount);
        goodsList.add(mango);

        BigDecimal totalPrice = commonCalculateService.calculateGoodsPrice(goodsList);
        System.out.println("price:"+totalPrice);
    }

    /**
     * 题目4:满减计算价格
     */
    @Test
    public void calculateGoodsPriceWithSubtract(){
        List<Goods> goodsList = new ArrayList<>();
        goodsList.add(apple);
        goodsList.add(strawberryWithDiscount);
        goodsList.add(mango);

        BigDecimal totalPrice = calculateWithSubtractService.calculateGoodsPrice(goodsList,subtract);
        System.out.println("price:"+totalPrice);
    }
}
